<?php

namespace App\Http\Controllers\Home\User;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Session;
use App\Http\Controllers\Home\User\Api\UserCenterApi;

class UserController extends Controller
{   
    protected $userdata;
    protected $userCenterApi;

    public function __construct(){

        $this->userdata = Session::get('home_user');
        $this->userCenterApi = new UserCenterApi;
    
    }


    //显示注册页面
    public function registerView()
    {
    	return view('Home/Register/register');
    }

    //显示登录页面
    public function loginView()
    {
    	return view('Home/Login/login');
    }

    //显示找回密码页面
     public function forgotpwdView()
    {
    	return view('Home/ForgotPassword/forgotpwd');
    }

    //显示重置密码页面
     public function resetpwdView(Request $Request,$Modifycondition)
    {   
        return view('Home/ResetPassword/resetpwd',['Modifycondition' => $Modifycondition]);
    }

    //显示用户中心页面
    public function usercenterView()
    {   
        $userinfo = $this->userdata;

        return view('Home/User/usercenter', [
            'userinfo' => $userinfo,
        ]);
    }

    //显示我的所有订单页面
    public function myorderView(Request $Request)
    {   
        $userorder = $this->userCenterApi->orders();
        //var_dump($userorder);

        return view('Home/User/order', [
            'userorder' => $userorder,
        ]);
    }

    //显示我的待付款订单页面
    public function myorder0View()
    {   
        $userorder = $this->userCenterApi->orders0();
        //var_dump($userorder);

        return view('Home/User/orderstate0', [
            'userorder' => $userorder,
        ]);
    }

    //显示我的待发货订单页面
    public function myorder1View()
    {   
        $userorder = $this->userCenterApi->orders1();
        //var_dump($userorder);

        return view('Home/User/orderstate1', [
            'userorder' => $userorder,
        ]);
    }

    //显示我的待收货订单页面
    public function myorder2View()
    {   
        $userorder = $this->userCenterApi->orders2();
        //var_dump($userorder);

        return view('Home/User/orderstate2', [
            'userorder' => $userorder,
        ]);
    }

     //显示我的订单详情页面
    public function myorders_detailView($oid)
    {   
        $userorder_detail = $this->userCenterApi->orders_details($oid);

         $orders = $userorder_detail[0];
         $orders_detalis = $userorder_detail[1];

        return view('Home/User/order_detail', [
            'orders_detalis' => $orders_detalis,
            'orders' => $orders,
        ]);
    }

     //显示我的收藏页面
    public function myfavouritesView()
    {   
        $userFaGoods = $this->userCenterApi->showFagoods();

        //dd($userorder_detail);

        // dd($userFaGoods[0]);
        return view('Home/User/favourites', ['userFaGoods' => $userFaGoods]);
    }

    //显示账号信息页面
    public function myaccountView()
    {   
         $userinfo = $this->userdata;

        return view('Home/User/account',[

            'userinfo' => $userinfo,
        ]);
    }

    //显示地址页面
    public function myaddressView()
    {   
        $useraddress = $this->userCenterApi->showaddress();
        return view('Home/User/address', [

            'useraddress' => $useraddress,
        ]);
    }

     //显示添加地址表单页面
    public function addAdView()
    {
        return view('Home/User/addAd');
    }

    public function editAdView($id)
    {   
        $aid = $id;
        return view('Home/User/editAd',['aid' => $aid]);
    }
}
